package semantic_network;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Menu_Chooser
{

    private static Properties props;

    /* Possible values of COMPARISON_MODE are
     * Method2
     * Method3
     * These are controlled through Properties file.
     */
    private static String COMPARISON_MODE = "COMPARISON_MODE";
    private static String SIMILARITY_METRIC = "SIMILARITY_METRIC";
    private static String DESCRIPTORS_PATH = "DESCRIPTORS_PATH";

    private static String database_url_1 = "database_url_1";
    private static String database_url_2 = "database_url_2";
    private static String username = "username";
    private static String password = "password";


    /*
     * This is te main function through which different methods of developing
     * Semantic Networds are called.
     */
    
    public static void main(String[] args)
    {
        props = new Properties();
        try
        {
            props.load(new FileInputStream("Semantic_Network.properties"));
        }
        catch (IOException ex)
        {
            Logger.getLogger(Menu_Chooser.class.getName()).log(Level.SEVERE, null, ex);
        }

        
        COMPARISON_MODE = props.getProperty(COMPARISON_MODE);
        SIMILARITY_METRIC = props.getProperty(SIMILARITY_METRIC);
        DESCRIPTORS_PATH = props.getProperty(DESCRIPTORS_PATH);

        database_url_1 = props.getProperty(database_url_1);
        database_url_2 = props.getProperty(database_url_2);
        username = props.getProperty(username);
        password = props.getProperty(password);


        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String input;
        try
        {
            System.out.println(
                    "*****************************************************");
            System.out.print(
                    "Please Choose among following options:\n" +
                    "*****************************************************\n" +
                    " 1.  Generate Network using lexical comparison of resource names \n" +
                    " 2.  Generate Network using [Inner product is measured using binary values (depending on existence/absence of descriptor)]\n " +
                    "     Method 2: for using shared descriptors and  \n " +
                    "     Method 3: for using lexical profiles of descriptors. \n " +
                    " 3.  Generate Network considering tf*idf using [Inner product is measured using tf*idf values of descriptors]\n " +
                    "     Method 2: for using shared descriptors and  \n " +
                    "     Method 3: for using lexical profiles of descriptors. \n " +

                    " Enter 'e' to exit : ");
            
            input = in.readLine();
            input = input.trim();

            if(input.equals("1"))
            {
                Resource_Handler resource_network = new Resource_Handler(database_url_1,database_url_2,username,password);
                resource_network.retrieve_resources_from_disk(DESCRIPTORS_PATH);
                resource_network.resource_matching_using_lexical_profiles(SIMILARITY_METRIC);
            }
            else if(input.equals("2"))
            {
                Resource_Handler resource_network = new Resource_Handler(database_url_1,database_url_2,username,password);
                resource_network.retrieve_resources_from_disk(DESCRIPTORS_PATH);
                resource_network.extract_descriptors();
                resource_network.resource_matching_using_descriptors(COMPARISON_MODE,SIMILARITY_METRIC);
            }

            else if (input.equals("3"))
            {
                Resource_Handler resource_network = new Resource_Handler(database_url_1,database_url_2,username,password);
                resource_network.retrieve_resources_from_disk(DESCRIPTORS_PATH);
                resource_network.extract_descriptors();
                resource_network.resource_matching_using_idf(COMPARISON_MODE);
            }
            else if (input.equals("e"))
            {
                System.exit(0);
            }
        }
        catch (Exception ex)
        {
            System.out.println("SQL Exception: Main Menu : " + ex.getMessage());
        }
    }
}
